<?php
namespace Admin\Controller;
use Think\Controller;
class LoginController extends Controller{
	function index(){
		$this->display();
	}
	function check(){
		
		$checkOb= M('manager');
		// admin 123456
		//先检查验证码是否正确
		 $verify=new \Think\Verify();
		 if(!$verify->check($_POST['verify'])){
		 	$this->error("验证码错误",U("Admin/Login/index"));
		 	exit();
		 }
		$password = MD5($_POST['password']);
		$username=$_POST['username'];
		$re = $checkOb->where("username = '%s' && password = '%s'",array($username,$password))
					  ->find();
		var_dump($re);
		if($re['status'] == '0'){
			$this->error('该账号已经被禁用,请联系管理员',U('Admin/Login/index'));
		}

		if($re){
			if($POST['onilne']== 1){
				$time = time()+3600*24*7;
			}else{
				$time = 0;
			}
			//创建会话变量
			//setcookie('adminid',$re);
			Session_start(); 
			setcookie('username',$re['username'],$time,'/');
			$_SESSION["username"] = $re["username"];
			$_SESSION["id"]=$re["id"];
			$this->redirect("Admin/Index/index");
		}else{
			$this->redirect("Admin/Login/index");
		}
	}
}